package com.wuwangfu.stream;

import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.FileProcessingMode;

/**
 * @Author jcshen
 * @Date 2023-02-21
 * @PackageName:com.wuwangfu.stream
 * @ClassName: DReadFile
 * @Description: TODO
 * @Version 1.0
 *
 * readFile 创建的Source是一个多并行度的Source，而且是一个无限的数据流，但是会重复读取数据
 */
public class DReadFile {
    public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        config.setInteger("rest.port",8181);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(config);

        String path = "flink-14/data";
        //每2秒检查文件是否有变化
        DataStreamSource<String> lines = env.readFile(new TextInputFormat(null), path,
                FileProcessingMode.PROCESS_CONTINUOUSLY, 2000);

        System.out.println(lines.getParallelism());

        lines.print();

        env.execute();

    }
}
